`NextRouter` was not mounted 您所在的位置:网站首页 Generating static pages 03TypeError Cannot `NextRouter` was not mounted

`NextRouter` was not mounted

2024-07-14 17:06| 来源: 网络整理| 查看: 265

`NextRouter` was not mountedWhy This Error Occurred

A component used useRouter outside a Next.js application, or was rendered outside a Next.js application. This can happen when doing unit testing on components that use the useRouter hook as they are not configured with Next.js' contexts.

This can also happen when you try to use the useRouter hook from next/router inside the app directory, as the App Router's useRouter from next/navigation has different behavior to the useRouter hook in pages.

Possible Ways to Fix It

If used in a test, mock out the router by mocking the next/router's useRouter() hook.

If used in the app directory, migrate to the new hooks imported from next/navigation.

Useful Links next-router-mock App Router Migration useRouter


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有